﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataEntity;
using Model;

namespace SWA_View
{
    public partial class FrequencyForm : Form
    {
        int _ProjectID = 0;
        ExperimentType _Type;
        public SpeedEntity Entity = null;
        public FrequencyForm(int id, int ProjectID, ExperimentType Type)
        {
            InitializeComponent();
            if (id > 0)
            {
                CommonModel com = new CommonModel();
                Entity = com.Query<SpeedEntity>("ID=" + id).FirstOrDefault();
                com = null;
            }
            if (Entity == null)
                Entity = new SpeedEntity() { ProjectID = ProjectID, ExperimentType = Type.ToString(), Type = SpeedEntityTyp.频率.ToString() };
            SetData();
        }


        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            GetData();
            DialogResult = DialogResult.OK;
        }

        private void GetData()
        {
            Entity.Speed = float.Parse(txtFrequency.Text);
        }

        private void txtRealLength_TextChanged(object sender, EventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (tb != null)
            {
                try
                {
                    double.Parse(tb.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("只能输入数字");
                    tb.Focus();
                    tb.Text = "0";
                }
            }
        }

        private void SetData()
        {
            txtFrequency.Text = Entity.Speed + "";
        }
    }
}
